import WatchValue, { SaveEmit, WatchType } from "../WatchValue";
import WatchNumber from '@/utils/WatchNumber';
import { RemoveSave } from "@/utils/RemoveSaveList";
import GradualNumber from "@/utils/GradualNumber";
import { ChangeCallBack } from "../GradualNumber";
import { ValueT } from "@/type";

/** 数值过渡监视类 */
export default class WatchGradualNumber {

	/** 过渡类 */
	private gradual: GradualNumber;

	/** 监视类 */
	private watch: WatchNumber;

	/** 监视类 */
	public get Watch() {
		return this.watch;
	}
	public set Watch(val: WatchNumber) {
		this.watch = val;
	}

	/** 过渡类 */
	public get Gradual() {
		return this.gradual;
	}
	public set Gradual(val: GradualNumber) {
		this.gradual = val;
	}

	/** 
	 * 初始值
	 * @override
	 */
	public get Start(): number {
		return this.gradual.Start;
	}

	/** 
	 * 当前值
	 * @override
	 */
	public get Value(): number {
		return this.gradual.Value;
	}
	public set Value(value: number) {
		this.gradual.Value = value;
	}

	/** 
	 * 目标值
	 * @override
	 */
	public get Target(): number {
		return this.gradual.Target;
	}


	/** 变化长度 */
	public get Length(): number {
		return this.gradual.Length;
	}

	/** 
	 * 变化次数
	 * @override
	 */
	public get Count(): WatchValue<number> {
		return this.gradual.Count;
	}
	public set Count(count: WatchValue<number>) {
		this.gradual.Count = count;
	}

	/** 
	 * 是否可以变化
	 * @override
	 */
	public get HasNext(): boolean {
		return this.gradual.HasNext;
	}

	/** 
	 * 变化进度
	 * @override
	 */
	public get Progress(): number {
		return this.gradual.Progress;
	}

	/** 
	 * 变化间距
	 * @override
	 */
	public get Space(): number {
		return this.gradual.Space;
	}

	/** 
	 * 渐变计算
	 * @override
	 */
	public get Changer(): ValueT<ChangeCallBack> {
		return this.gradual.Changer;
	}
	public set Changer(changer: ValueT<ChangeCallBack>) {
		this.gradual.Changer = changer;
	}

	/**
	 * 构造函数
	 * @param value 初始值
	 * @param count 变化帧数
	 * @param transition 变化方式
	 */
	public constructor(value: number, count: WatchValue<number> | number, changer: ValueT<ChangeCallBack>) {
		this.watch = new WatchNumber(value);
		this.gradual = new GradualNumber(value, count, changer);
	}

	/**
	 * 添加数据变化事件
	 * @param traget 绑定对象
	 * @param event 绑定事件
	 * @param deep 是否未深度绑定
	 * @override
	 */
	public Add(traget: any, event: () => void, deep?: boolean): void {
		return this.watch.Add(traget, event);
	}

	/** 
	 * 触发变更监视
	 * @override
	 */
	public Trigger(): void {
		const { gradual, watch } = this;
		gradual.Trigger();
		watch.Value = gradual.Value;
	}
}
